{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>x1</th>\n",
       "      <th>x2</th>\n",
       "      <th>x3</th>\n",
       "      <th>x4</th>\n",
       "      <th>x5</th>\n",
       "      <th>x6</th>\n",
       "      <th>x7</th>\n",
       "      <th>x8</th>\n",
       "      <th>x9</th>\n",
       "      <th>x10</th>\n",
       "      <th>x11</th>\n",
       "      <th>x12</th>\n",
       "      <th>x13</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3831732</td>\n",
       "      <td>181.54</td>\n",
       "      <td>448.19</td>\n",
       "      <td>7571.00</td>\n",
       "      <td>6212.70</td>\n",
       "      <td>6370241</td>\n",
       "      <td>525.71</td>\n",
       "      <td>985.31</td>\n",
       "      <td>60.62</td>\n",
       "      <td>65.66</td>\n",
       "      <td>120.0</td>\n",
       "      <td>1.029</td>\n",
       "      <td>5321</td>\n",
       "      <td>64.87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3913824</td>\n",
       "      <td>214.63</td>\n",
       "      <td>549.97</td>\n",
       "      <td>9038.16</td>\n",
       "      <td>7601.73</td>\n",
       "      <td>6467115</td>\n",
       "      <td>618.25</td>\n",
       "      <td>1259.20</td>\n",
       "      <td>73.46</td>\n",
       "      <td>95.46</td>\n",
       "      <td>113.5</td>\n",
       "      <td>1.051</td>\n",
       "      <td>6529</td>\n",
       "      <td>99.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3928907</td>\n",
       "      <td>239.56</td>\n",
       "      <td>686.44</td>\n",
       "      <td>9905.31</td>\n",
       "      <td>8092.82</td>\n",
       "      <td>6560508</td>\n",
       "      <td>638.94</td>\n",
       "      <td>1468.06</td>\n",
       "      <td>81.16</td>\n",
       "      <td>81.16</td>\n",
       "      <td>108.2</td>\n",
       "      <td>1.064</td>\n",
       "      <td>7008</td>\n",
       "      <td>88.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4282130</td>\n",
       "      <td>261.58</td>\n",
       "      <td>802.59</td>\n",
       "      <td>10444.60</td>\n",
       "      <td>8767.98</td>\n",
       "      <td>6664862</td>\n",
       "      <td>656.58</td>\n",
       "      <td>1678.12</td>\n",
       "      <td>85.72</td>\n",
       "      <td>91.70</td>\n",
       "      <td>102.2</td>\n",
       "      <td>1.092</td>\n",
       "      <td>7694</td>\n",
       "      <td>106.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4453911</td>\n",
       "      <td>283.14</td>\n",
       "      <td>904.57</td>\n",
       "      <td>11255.70</td>\n",
       "      <td>9422.33</td>\n",
       "      <td>6741400</td>\n",
       "      <td>758.83</td>\n",
       "      <td>1893.52</td>\n",
       "      <td>88.88</td>\n",
       "      <td>114.61</td>\n",
       "      <td>97.7</td>\n",
       "      <td>1.200</td>\n",
       "      <td>8027</td>\n",
       "      <td>137.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>4548852</td>\n",
       "      <td>308.58</td>\n",
       "      <td>1000.69</td>\n",
       "      <td>12018.52</td>\n",
       "      <td>9751.44</td>\n",
       "      <td>6850024</td>\n",
       "      <td>878.26</td>\n",
       "      <td>2139.18</td>\n",
       "      <td>92.85</td>\n",
       "      <td>152.78</td>\n",
       "      <td>98.5</td>\n",
       "      <td>1.198</td>\n",
       "      <td>8549</td>\n",
       "      <td>188.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>4962579</td>\n",
       "      <td>348.09</td>\n",
       "      <td>1121.13</td>\n",
       "      <td>13966.53</td>\n",
       "      <td>11349.47</td>\n",
       "      <td>7006896</td>\n",
       "      <td>923.67</td>\n",
       "      <td>2492.74</td>\n",
       "      <td>94.37</td>\n",
       "      <td>170.62</td>\n",
       "      <td>102.8</td>\n",
       "      <td>1.348</td>\n",
       "      <td>9566</td>\n",
       "      <td>219.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>5029338</td>\n",
       "      <td>387.81</td>\n",
       "      <td>1248.29</td>\n",
       "      <td>14694.00</td>\n",
       "      <td>11467.35</td>\n",
       "      <td>7125979</td>\n",
       "      <td>978.21</td>\n",
       "      <td>2841.65</td>\n",
       "      <td>97.28</td>\n",
       "      <td>214.53</td>\n",
       "      <td>98.9</td>\n",
       "      <td>1.467</td>\n",
       "      <td>10473</td>\n",
       "      <td>271.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5070216</td>\n",
       "      <td>453.49</td>\n",
       "      <td>1370.68</td>\n",
       "      <td>13380.47</td>\n",
       "      <td>10671.78</td>\n",
       "      <td>7206229</td>\n",
       "      <td>1009.24</td>\n",
       "      <td>3203.96</td>\n",
       "      <td>103.07</td>\n",
       "      <td>202.18</td>\n",
       "      <td>97.6</td>\n",
       "      <td>1.560</td>\n",
       "      <td>11469</td>\n",
       "      <td>269.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>5210706</td>\n",
       "      <td>533.55</td>\n",
       "      <td>1494.27</td>\n",
       "      <td>15002.59</td>\n",
       "      <td>11570.58</td>\n",
       "      <td>7251888</td>\n",
       "      <td>1175.17</td>\n",
       "      <td>3758.62</td>\n",
       "      <td>109.91</td>\n",
       "      <td>222.51</td>\n",
       "      <td>100.1</td>\n",
       "      <td>1.456</td>\n",
       "      <td>12360</td>\n",
       "      <td>300.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>5407087</td>\n",
       "      <td>598.33</td>\n",
       "      <td>1677.77</td>\n",
       "      <td>16884.16</td>\n",
       "      <td>13120.83</td>\n",
       "      <td>7376720</td>\n",
       "      <td>1348.93</td>\n",
       "      <td>4450.55</td>\n",
       "      <td>117.15</td>\n",
       "      <td>249.01</td>\n",
       "      <td>101.7</td>\n",
       "      <td>1.424</td>\n",
       "      <td>14174</td>\n",
       "      <td>338.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5744550</td>\n",
       "      <td>665.32</td>\n",
       "      <td>1905.84</td>\n",
       "      <td>18287.24</td>\n",
       "      <td>14468.24</td>\n",
       "      <td>7505322</td>\n",
       "      <td>1519.16</td>\n",
       "      <td>5154.23</td>\n",
       "      <td>130.22</td>\n",
       "      <td>303.41</td>\n",
       "      <td>101.5</td>\n",
       "      <td>1.456</td>\n",
       "      <td>16394</td>\n",
       "      <td>408.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>5994973</td>\n",
       "      <td>738.97</td>\n",
       "      <td>2199.14</td>\n",
       "      <td>19850.66</td>\n",
       "      <td>15444.93</td>\n",
       "      <td>7607220</td>\n",
       "      <td>1696.38</td>\n",
       "      <td>6081.86</td>\n",
       "      <td>128.51</td>\n",
       "      <td>356.99</td>\n",
       "      <td>102.3</td>\n",
       "      <td>1.438</td>\n",
       "      <td>17881</td>\n",
       "      <td>476.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>6236312</td>\n",
       "      <td>877.07</td>\n",
       "      <td>2624.24</td>\n",
       "      <td>22469.22</td>\n",
       "      <td>18951.32</td>\n",
       "      <td>7734787</td>\n",
       "      <td>1863.34</td>\n",
       "      <td>7140.32</td>\n",
       "      <td>149.87</td>\n",
       "      <td>429.36</td>\n",
       "      <td>103.4</td>\n",
       "      <td>1.474</td>\n",
       "      <td>20058</td>\n",
       "      <td>838.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>6529045</td>\n",
       "      <td>1005.37</td>\n",
       "      <td>3187.39</td>\n",
       "      <td>25316.72</td>\n",
       "      <td>20835.95</td>\n",
       "      <td>7841695</td>\n",
       "      <td>2105.54</td>\n",
       "      <td>8287.38</td>\n",
       "      <td>169.19</td>\n",
       "      <td>508.84</td>\n",
       "      <td>105.9</td>\n",
       "      <td>1.515</td>\n",
       "      <td>22114</td>\n",
       "      <td>843.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>6791495</td>\n",
       "      <td>1118.03</td>\n",
       "      <td>3615.77</td>\n",
       "      <td>27609.59</td>\n",
       "      <td>22820.89</td>\n",
       "      <td>7946154</td>\n",
       "      <td>2659.85</td>\n",
       "      <td>9138.21</td>\n",
       "      <td>172.28</td>\n",
       "      <td>557.74</td>\n",
       "      <td>97.5</td>\n",
       "      <td>1.633</td>\n",
       "      <td>24190</td>\n",
       "      <td>1107.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>7110695</td>\n",
       "      <td>1304.48</td>\n",
       "      <td>4476.38</td>\n",
       "      <td>30658.49</td>\n",
       "      <td>25011.61</td>\n",
       "      <td>8061370</td>\n",
       "      <td>3263.57</td>\n",
       "      <td>10748.28</td>\n",
       "      <td>188.57</td>\n",
       "      <td>664.06</td>\n",
       "      <td>103.2</td>\n",
       "      <td>1.638</td>\n",
       "      <td>29549</td>\n",
       "      <td>1399.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>7431755</td>\n",
       "      <td>1700.87</td>\n",
       "      <td>5243.03</td>\n",
       "      <td>34438.08</td>\n",
       "      <td>28209.74</td>\n",
       "      <td>8145797</td>\n",
       "      <td>3412.21</td>\n",
       "      <td>12423.44</td>\n",
       "      <td>204.54</td>\n",
       "      <td>710.66</td>\n",
       "      <td>105.5</td>\n",
       "      <td>1.670</td>\n",
       "      <td>34214</td>\n",
       "      <td>1535.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>7512997</td>\n",
       "      <td>1969.51</td>\n",
       "      <td>5977.27</td>\n",
       "      <td>38053.52</td>\n",
       "      <td>30490.44</td>\n",
       "      <td>8222969</td>\n",
       "      <td>3758.39</td>\n",
       "      <td>13551.21</td>\n",
       "      <td>213.76</td>\n",
       "      <td>760.49</td>\n",
       "      <td>103.0</td>\n",
       "      <td>1.825</td>\n",
       "      <td>37934</td>\n",
       "      <td>1579.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>7599295</td>\n",
       "      <td>2110.78</td>\n",
       "      <td>6882.85</td>\n",
       "      <td>42049.14</td>\n",
       "      <td>33156.83</td>\n",
       "      <td>8323096</td>\n",
       "      <td>4454.55</td>\n",
       "      <td>15420.14</td>\n",
       "      <td>228.46</td>\n",
       "      <td>852.56</td>\n",
       "      <td>102.6</td>\n",
       "      <td>1.906</td>\n",
       "      <td>41972</td>\n",
       "      <td>2088.14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         x1       x2       x3        x4        x5       x6       x7        x8  \\\n",
       "0   3831732   181.54   448.19   7571.00   6212.70  6370241   525.71    985.31   \n",
       "1   3913824   214.63   549.97   9038.16   7601.73  6467115   618.25   1259.20   \n",
       "2   3928907   239.56   686.44   9905.31   8092.82  6560508   638.94   1468.06   \n",
       "3   4282130   261.58   802.59  10444.60   8767.98  6664862   656.58   1678.12   \n",
       "4   4453911   283.14   904.57  11255.70   9422.33  6741400   758.83   1893.52   \n",
       "5   4548852   308.58  1000.69  12018.52   9751.44  6850024   878.26   2139.18   \n",
       "6   4962579   348.09  1121.13  13966.53  11349.47  7006896   923.67   2492.74   \n",
       "7   5029338   387.81  1248.29  14694.00  11467.35  7125979   978.21   2841.65   \n",
       "8   5070216   453.49  1370.68  13380.47  10671.78  7206229  1009.24   3203.96   \n",
       "9   5210706   533.55  1494.27  15002.59  11570.58  7251888  1175.17   3758.62   \n",
       "10  5407087   598.33  1677.77  16884.16  13120.83  7376720  1348.93   4450.55   \n",
       "11  5744550   665.32  1905.84  18287.24  14468.24  7505322  1519.16   5154.23   \n",
       "12  5994973   738.97  2199.14  19850.66  15444.93  7607220  1696.38   6081.86   \n",
       "13  6236312   877.07  2624.24  22469.22  18951.32  7734787  1863.34   7140.32   \n",
       "14  6529045  1005.37  3187.39  25316.72  20835.95  7841695  2105.54   8287.38   \n",
       "15  6791495  1118.03  3615.77  27609.59  22820.89  7946154  2659.85   9138.21   \n",
       "16  7110695  1304.48  4476.38  30658.49  25011.61  8061370  3263.57  10748.28   \n",
       "17  7431755  1700.87  5243.03  34438.08  28209.74  8145797  3412.21  12423.44   \n",
       "18  7512997  1969.51  5977.27  38053.52  30490.44  8222969  3758.39  13551.21   \n",
       "19  7599295  2110.78  6882.85  42049.14  33156.83  8323096  4454.55  15420.14   \n",
       "\n",
       "        x9     x10    x11    x12    x13        y  \n",
       "0    60.62   65.66  120.0  1.029   5321    64.87  \n",
       "1    73.46   95.46  113.5  1.051   6529    99.75  \n",
       "2    81.16   81.16  108.2  1.064   7008    88.11  \n",
       "3    85.72   91.70  102.2  1.092   7694   106.07  \n",
       "4    88.88  114.61   97.7  1.200   8027   137.32  \n",
       "5    92.85  152.78   98.5  1.198   8549   188.14  \n",
       "6    94.37  170.62  102.8  1.348   9566   219.91  \n",
       "7    97.28  214.53   98.9  1.467  10473   271.91  \n",
       "8   103.07  202.18   97.6  1.560  11469   269.10  \n",
       "9   109.91  222.51  100.1  1.456  12360   300.55  \n",
       "10  117.15  249.01  101.7  1.424  14174   338.45  \n",
       "11  130.22  303.41  101.5  1.456  16394   408.86  \n",
       "12  128.51  356.99  102.3  1.438  17881   476.72  \n",
       "13  149.87  429.36  103.4  1.474  20058   838.99  \n",
       "14  169.19  508.84  105.9  1.515  22114   843.14  \n",
       "15  172.28  557.74   97.5  1.633  24190  1107.67  \n",
       "16  188.57  664.06  103.2  1.638  29549  1399.16  \n",
       "17  204.54  710.66  105.5  1.670  34214  1535.14  \n",
       "18  213.76  760.49  103.0  1.825  37934  1579.68  \n",
       "19  228.46  852.56  102.6  1.906  41972  2088.14  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#-*- coding:utf-8 -*-\n",
    "# 2_1 某市财政收入预测模型\n",
    "# 2_1_1 变量选择模型，本小节中书中使用的是AdaptiveLasso，但是没有找到该函数，所以采用了其他变量选择模型\n",
    "# 书中给出的选出的变量为'x1', 'x2', 'x3', 'x4', 'x5', 'x7'\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "inputfile1 = 'data1.csv'\n",
    "data = pd.read_csv(inputfile1)\n",
    "data # 1994到2013年间的各个影响因素的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# # 注意：此段代码无法运行：没有找到该函数\n",
    "# # 导入AdaptiveLasso包\n",
    "# from sklearn.linear_model import AdaptiveLasso\n",
    "# model = AdaptiveLasso(gamma = 1)\n",
    "# model.fit(data.iloc[:, 0:13], data['y'])\n",
    "# model.coef_# 各个特征的系数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ -8.93790273e-05  -5.12404003e-01   2.12890396e-01  -4.14066742e-02\n",
      "   8.00575771e-02   3.18378090e-01]\n",
      "1.74923516819\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import Lasso# AdaptiveLasso找不到\n",
    "# LASSO回归的特点是在拟合广义线性模型的同时进行变量筛选和复杂度调整。 因此，不论目标因变量是连续的，还是二元或者多元离散的，\n",
    "#都可以用LASSO回归建模然后预测。 这里的变量筛选是指不把所有的变量都放入模型中进行拟合，而是有选择的把变量放入模型从而得到更好的性能参数。\n",
    "model = Lasso(alpha=0.1)\n",
    "model.fit(data[['x1', 'x2', 'x3', 'x4','x5', 'x7']], data['y']) # data.iloc[:, 0:13]\n",
    "print model.coef_ # 各个特征的系数\n",
    "print model.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ -2.23346221e-05   0.00000000e+00  -5.87867983e-03   0.00000000e+00\n",
      "   2.22231308e-02  -1.62221180e-04   3.13480155e-01   0.00000000e+00\n",
      "   0.00000000e+00   7.37836808e-01   2.37577442e-01   0.00000000e+00\n",
      "   0.00000000e+00]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import Lars #最小角回归\n",
    "model1 = Lars(n_nonzero_coefs = 7)\n",
    "model1.fit(data.iloc[:, 0:13], data['y'])\n",
    "print model1.coef_ # 各个特征的系数\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.          0.          0.06028917  0.          0.01227839  0.\n",
      "  0.32712489  0.          0.          0.          2.73312783  0.          0.        ]\n",
      "1.1391362844\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda2\\lib\\site-packages\\sklearn\\linear_model\\least_angle.py:313: ConvergenceWarning: Regressors in active set degenerate. Dropping a regressor, after 16 iterations, i.e. alpha=4.027e-02, with an active set of 12 regressors, and the smallest cholesky pivot element being 6.909e-08. Reduce max_iter or increase eps parameters.\n",
      "  ConvergenceWarning)\n"
     ]
    }
   ],
   "source": [
    "# 确定最合适的Alpha\n",
    "from sklearn.linear_model import LarsCV #交叉验证最小二乘法回归模型\n",
    "model1 = LarsCV()\n",
    "model1.fit(data.iloc[:, 0:13], data['y'])\n",
    "print model1.coef_ # 各个特征的系数\n",
    "print model1.alpha_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.00124055  0.          0.          0.          0.         -0.00161083\n",
      "  0.          0.          0.          0.          0.          0.          0.        ]\n",
      "685733.826903\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LassoCV #交叉验证最小二乘法回归模型\n",
    "model1 = LassoCV()\n",
    "model1.fit(data.iloc[:, 0:13], data['y'])\n",
    "print model1.coef_ # 各个特征的系数\n",
    "print model1.alpha_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ -1.88512448e-04  -2.68436321e-01   4.45960813e-01  -3.24264041e-02\n",
      "   7.25657667e-02   4.52109484e-04   2.28596158e-01  -4.51460904e-02\n",
      "  -3.10503208e+00   6.19423002e-01   4.80398130e+00  -9.79664624e+01\n",
      "  -3.86933684e-02]\n",
      "-2650.99589437\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import Lasso# AdaptiveLasso找不到\n",
    "# LASSO回归的特点是在拟合广义线性模型的同时进行变量筛选和复杂度调整。 因此，不论目标因变量是连续的，还是二元或者多元离散的，\n",
    "#都可以用LASSO回归建模然后预测。 这里的变量筛选是指不把所有的变量都放入模型中进行拟合，而是有选择的把变量放入模型从而得到更好的性能参数。\n",
    "model = Lasso(alpha = 0.1)\n",
    "model.fit(data.iloc[:,:13], data['y']) # data.iloc[:, 0:13]\n",
    "print model.coef_ # 各个特征的系数\n",
    "print model.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "耗费时间为46.1783953278s!\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lassovalue</th>\n",
       "      <th>absLasso</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x4', 'x7', 'x8', 'x11', 'x12']</th>\n",
       "      <td>-0.0890884</td>\n",
       "      <td>0.0890884</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x3', 'x6', 'x7', 'x8', 'x10', 'x11', 'x13']</th>\n",
       "      <td>0.276445</td>\n",
       "      <td>0.276445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x4', 'x5', 'x7', 'x8', 'x11', 'x13']</th>\n",
       "      <td>0.337246</td>\n",
       "      <td>0.337246</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x5', 'x7', 'x8', 'x9', 'x12']</th>\n",
       "      <td>0.541261</td>\n",
       "      <td>0.541261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x4', 'x6', 'x9', 'x10', 'x11', 'x13']</th>\n",
       "      <td>0.583118</td>\n",
       "      <td>0.583118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x3', 'x4', 'x12']</th>\n",
       "      <td>-0.764101</td>\n",
       "      <td>0.764101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x3', 'x5', 'x8', 'x10', 'x13']</th>\n",
       "      <td>0.829183</td>\n",
       "      <td>0.829183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x4', 'x7', 'x9']</th>\n",
       "      <td>0.842587</td>\n",
       "      <td>0.842587</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x4', 'x7', 'x8', 'x11', 'x13']</th>\n",
       "      <td>-0.859084</td>\n",
       "      <td>0.859084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x4', 'x5', 'x7', 'x12']</th>\n",
       "      <td>-0.983955</td>\n",
       "      <td>0.983955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x3', 'x5', 'x7', 'x8', 'x9']</th>\n",
       "      <td>1.12529</td>\n",
       "      <td>1.12529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x4', 'x7', 'x8', 'x9', 'x10', 'x13']</th>\n",
       "      <td>1.12572</td>\n",
       "      <td>1.12572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x3', 'x5', 'x7', 'x10', 'x12']</th>\n",
       "      <td>1.17751</td>\n",
       "      <td>1.17751</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x4', 'x5', 'x9', 'x13']</th>\n",
       "      <td>1.22661</td>\n",
       "      <td>1.22661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x7', 'x9', 'x12']</th>\n",
       "      <td>-1.41554</td>\n",
       "      <td>1.41554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x4', 'x7', 'x10', 'x11', 'x13']</th>\n",
       "      <td>-1.47046</td>\n",
       "      <td>1.47046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x5', 'x9']</th>\n",
       "      <td>-1.47639</td>\n",
       "      <td>1.47639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x5', 'x7', 'x9', 'x13']</th>\n",
       "      <td>1.53122</td>\n",
       "      <td>1.53122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x4', 'x5', 'x8', 'x10', 'x12']</th>\n",
       "      <td>-1.72649</td>\n",
       "      <td>1.72649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x4', 'x5', 'x7']</th>\n",
       "      <td>1.74924</td>\n",
       "      <td>1.74924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x4', 'x5', 'x13']</th>\n",
       "      <td>1.76035</td>\n",
       "      <td>1.76035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x4', 'x5', 'x7', 'x9', 'x12']</th>\n",
       "      <td>1.97432</td>\n",
       "      <td>1.97432</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x6', 'x10', 'x13']</th>\n",
       "      <td>2.0534</td>\n",
       "      <td>2.0534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x4']</th>\n",
       "      <td>2.1727</td>\n",
       "      <td>2.1727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x3', 'x5', 'x6', 'x7', 'x10']</th>\n",
       "      <td>-2.23228</td>\n",
       "      <td>2.23228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x3', 'x5', 'x10', 'x11', 'x12', 'x13']</th>\n",
       "      <td>-2.69529</td>\n",
       "      <td>2.69529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x3', 'x5', 'x7', 'x9', 'x12']</th>\n",
       "      <td>2.80973</td>\n",
       "      <td>2.80973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x3', 'x9', 'x10', 'x11']</th>\n",
       "      <td>3.17667</td>\n",
       "      <td>3.17667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x3', 'x5', 'x6', 'x7', 'x8', 'x11', 'x12']</th>\n",
       "      <td>3.21465</td>\n",
       "      <td>3.21465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x5', 'x8', 'x10', 'x12', 'x13']</th>\n",
       "      <td>3.2311</td>\n",
       "      <td>3.2311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x4', 'x6', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4418.51</td>\n",
       "      <td>4418.51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x4', 'x6', 'x8', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4444.81</td>\n",
       "      <td>4444.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x10', 'x11', 'x13']</th>\n",
       "      <td>4494.96</td>\n",
       "      <td>4494.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x12']</th>\n",
       "      <td>4513.43</td>\n",
       "      <td>4513.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x6', 'x8', 'x9', 'x12']</th>\n",
       "      <td>4514.49</td>\n",
       "      <td>4514.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x13']</th>\n",
       "      <td>4533.84</td>\n",
       "      <td>4533.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x4', 'x6', 'x8', 'x10', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4590.04</td>\n",
       "      <td>4590.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x6', 'x11']</th>\n",
       "      <td>4681.96</td>\n",
       "      <td>4681.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x12']</th>\n",
       "      <td>4711.91</td>\n",
       "      <td>4711.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x12', 'x13']</th>\n",
       "      <td>4716.28</td>\n",
       "      <td>4716.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x10', 'x11', 'x12']</th>\n",
       "      <td>4725.61</td>\n",
       "      <td>4725.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x6', 'x8', 'x9', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4829.14</td>\n",
       "      <td>4829.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x6', 'x8', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4844.56</td>\n",
       "      <td>4844.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x11', 'x12']</th>\n",
       "      <td>4873.03</td>\n",
       "      <td>4873.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4882.17</td>\n",
       "      <td>4882.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x10', 'x11', 'x12', 'x13']</th>\n",
       "      <td>4971.69</td>\n",
       "      <td>4971.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x11', 'x12']</th>\n",
       "      <td>5054.45</td>\n",
       "      <td>5054.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x6', 'x8', 'x9', 'x11', 'x12']</th>\n",
       "      <td>5059.16</td>\n",
       "      <td>5059.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x2', 'x6', 'x8', 'x11', 'x12']</th>\n",
       "      <td>5116.79</td>\n",
       "      <td>5116.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x11', 'x12', 'x13']</th>\n",
       "      <td>5126.49</td>\n",
       "      <td>5126.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x6', 'x9', 'x12']</th>\n",
       "      <td>5191.6</td>\n",
       "      <td>5191.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x2', 'x6', 'x8', 'x9', 'x11', 'x12', 'x13']</th>\n",
       "      <td>5258.97</td>\n",
       "      <td>5258.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x6', 'x11', 'x12']</th>\n",
       "      <td>5370.68</td>\n",
       "      <td>5370.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x6', 'x12']</th>\n",
       "      <td>-5725.66</td>\n",
       "      <td>5725.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x6']</th>\n",
       "      <td>-5934</td>\n",
       "      <td>5934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x11', 'x12']</th>\n",
       "      <td>-6388.05</td>\n",
       "      <td>6388.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x6']</th>\n",
       "      <td>6559.97</td>\n",
       "      <td>6559.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x1', 'x6', 'x12']</th>\n",
       "      <td>8171.3</td>\n",
       "      <td>8171.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x6', 'x11', 'x12']</th>\n",
       "      <td>-8369.75</td>\n",
       "      <td>8369.75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>['x6', 'x11']</th>\n",
       "      <td>-8949.07</td>\n",
       "      <td>8949.07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8191 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   lassovalue   absLasso\n",
       "index                                                                   \n",
       "['x1', 'x2', 'x4', 'x7', 'x8', 'x11', 'x12']       -0.0890884  0.0890884\n",
       "['x2', 'x3', 'x6', 'x7', 'x8', 'x10', 'x11', 'x...   0.276445   0.276445\n",
       "['x1', 'x4', 'x5', 'x7', 'x8', 'x11', 'x13']         0.337246   0.337246\n",
       "['x1', 'x3', 'x5', 'x7', 'x8', 'x9', 'x12']          0.541261   0.541261\n",
       "['x1', 'x3', 'x4', 'x6', 'x9', 'x10', 'x11', 'x...   0.583118   0.583118\n",
       "['x3', 'x4', 'x12']                                 -0.764101   0.764101\n",
       "['x2', 'x3', 'x5', 'x8', 'x10', 'x13']               0.829183   0.829183\n",
       "['x1', 'x4', 'x7', 'x9']                             0.842587   0.842587\n",
       "['x1', 'x4', 'x7', 'x8', 'x11', 'x13']              -0.859084   0.859084\n",
       "['x1', 'x2', 'x4', 'x5', 'x7', 'x12']               -0.983955   0.983955\n",
       "['x2', 'x3', 'x5', 'x7', 'x8', 'x9']                  1.12529    1.12529\n",
       "['x2', 'x4', 'x7', 'x8', 'x9', 'x10', 'x13']          1.12572    1.12572\n",
       "['x2', 'x3', 'x5', 'x7', 'x10', 'x12']                1.17751    1.17751\n",
       "['x1', 'x2', 'x3', 'x4', 'x5', 'x9', 'x13']           1.22661    1.22661\n",
       "['x1', 'x3', 'x7', 'x9', 'x12']                      -1.41554    1.41554\n",
       "['x1', 'x3', 'x4', 'x7', 'x10', 'x11', 'x13']        -1.47046    1.47046\n",
       "['x1', 'x3', 'x5', 'x9']                             -1.47639    1.47639\n",
       "['x1', 'x2', 'x3', 'x5', 'x7', 'x9', 'x13']           1.53122    1.53122\n",
       "['x2', 'x4', 'x5', 'x8', 'x10', 'x12']               -1.72649    1.72649\n",
       "['x1', 'x2', 'x3', 'x4', 'x5', 'x7']                  1.74924    1.74924\n",
       "['x1', 'x2', 'x3', 'x4', 'x5', 'x13']                 1.76035    1.76035\n",
       "['x1', 'x3', 'x4', 'x5', 'x7', 'x9', 'x12']           1.97432    1.97432\n",
       "['x1', 'x2', 'x3', 'x6', 'x10', 'x13']                 2.0534     2.0534\n",
       "['x1', 'x4']                                           2.1727     2.1727\n",
       "['x1', 'x3', 'x5', 'x6', 'x7', 'x10']                -2.23228    2.23228\n",
       "['x3', 'x5', 'x10', 'x11', 'x12', 'x13']             -2.69529    2.69529\n",
       "['x1', 'x2', 'x3', 'x5', 'x7', 'x9', 'x12']           2.80973    2.80973\n",
       "['x3', 'x9', 'x10', 'x11']                            3.17667    3.17667\n",
       "['x2', 'x3', 'x5', 'x6', 'x7', 'x8', 'x11', 'x12']    3.21465    3.21465\n",
       "['x2', 'x5', 'x8', 'x10', 'x12', 'x13']                3.2311     3.2311\n",
       "...                                                       ...        ...\n",
       "['x2', 'x4', 'x6', 'x8', 'x9', 'x10', 'x11', 'x...    4418.51    4418.51\n",
       "['x2', 'x4', 'x6', 'x8', 'x11', 'x12', 'x13']         4444.81    4444.81\n",
       "['x2', 'x6', 'x8', 'x10', 'x11', 'x13']               4494.96    4494.96\n",
       "['x2', 'x6', 'x8', 'x9', 'x12']                       4513.43    4513.43\n",
       "['x1', 'x2', 'x6', 'x8', 'x9', 'x12']                 4514.49    4514.49\n",
       "['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x13']         4533.84    4533.84\n",
       "['x2', 'x4', 'x6', 'x8', 'x10', 'x11', 'x12', '...    4590.04    4590.04\n",
       "['x1', 'x6', 'x11']                                   4681.96    4681.96\n",
       "['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x12']         4711.91    4711.91\n",
       "['x2', 'x6', 'x8', 'x9', 'x12', 'x13']                4716.28    4716.28\n",
       "['x2', 'x6', 'x8', 'x10', 'x11', 'x12']               4725.61    4725.61\n",
       "['x1', 'x2', 'x6', 'x8', 'x9', 'x11', 'x12', 'x...    4829.14    4829.14\n",
       "['x1', 'x2', 'x6', 'x8', 'x11', 'x12', 'x13']         4844.56    4844.56\n",
       "['x2', 'x6', 'x8', 'x11', 'x12']                      4873.03    4873.03\n",
       "['x2', 'x6', 'x8', 'x9', 'x10', 'x11', 'x12', '...    4882.17    4882.17\n",
       "['x2', 'x6', 'x8', 'x10', 'x11', 'x12', 'x13']        4971.69    4971.69\n",
       "['x2', 'x6', 'x8', 'x9', 'x11', 'x12']                5054.45    5054.45\n",
       "['x1', 'x2', 'x6', 'x8', 'x9', 'x11', 'x12']          5059.16    5059.16\n",
       "['x1', 'x2', 'x6', 'x8', 'x11', 'x12']                5116.79    5116.79\n",
       "['x2', 'x6', 'x8', 'x11', 'x12', 'x13']               5126.49    5126.49\n",
       "['x1', 'x6', 'x9', 'x12']                              5191.6     5191.6\n",
       "['x2', 'x6', 'x8', 'x9', 'x11', 'x12', 'x13']         5258.97    5258.97\n",
       "['x1', 'x6', 'x11', 'x12']                            5370.68    5370.68\n",
       "['x6', 'x12']                                        -5725.66    5725.66\n",
       "['x6']                                                  -5934       5934\n",
       "['x11', 'x12']                                       -6388.05    6388.05\n",
       "['x1', 'x6']                                          6559.97    6559.97\n",
       "['x1', 'x6', 'x12']                                    8171.3     8171.3\n",
       "['x6', 'x11', 'x12']                                 -8369.75    8369.75\n",
       "['x6', 'x11']                                        -8949.07    8949.07\n",
       "\n",
       "[8191 rows x 2 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分析合适的Lasso变量组合\n",
    "import itertools\n",
    "from sklearn.linear_model import Lasso   # AdaptiveLasso找不到\n",
    "import time \n",
    "start = time.clock()\n",
    "a = data.columns[:13]\n",
    "tempdf = pd.DataFrame([])\n",
    "for i in range(1,len(a)+1):\n",
    "    All = list(itertools.combinations(a,i))\n",
    "    for j in range(len(All)):\n",
    "        model = Lasso(alpha=0.1)\n",
    "        model.fit(data[list(All[j])], data['y']) # data.iloc[:, 0:13]\n",
    "        effect = model.intercept_\n",
    "        tempdf = tempdf.append([str(list(All[j])), effect])\n",
    "end = time.clock()\n",
    "print '耗费时间为' + str(end-start) +'s!'\n",
    "\n",
    "res1 = pd.DataFrame(tempdf[tempdf.index == 1 ][0])\n",
    "res1.columns = ['lassovalue']\n",
    "res1.head() # len(res)=8191\n",
    "res1['index'] = tempdf[tempdf.index == 0 ][0].values\n",
    "res = res1.set_index('index')\n",
    "res['absLasso'] = np.abs(res['lassovalue'].values)\n",
    "res.sort_values(by = 'absLasso')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ -3.84466588e-04  -5.94732411e-01   4.29000036e-01  -1.24925239e-01\n",
      "   1.74154990e-01   7.96690107e-04   2.67402903e-01   3.25616769e-02\n",
      "  -7.45099551e+00  -1.00039680e-01   3.35606121e+00   1.67651891e+01\n",
      "  -7.05283320e-03]\n",
      "-3858.30874757\n",
      "0.997670764939\n",
      "{'normalize': False, 'fit_intercept': True, 'max_iter': None, 'random_state': None, 'tol': 0.001, 'copy_X': True, 'alpha': 0.1, 'solver': 'auto'}\n",
      "Ridge(alpha=0.1, copy_X=True, fit_intercept=False, max_iter=None,\n",
      "   normalize=False, random_state=None, solver='auto', tol=0.001)\n"
     ]
    }
   ],
   "source": [
    "# 岭回归（Ridge 回归）\n",
    "from sklearn import linear_model\n",
    "clf = linear_model.Ridge(alpha=0.1)  # 设置k值\n",
    "clf.fit(data.iloc[:, 0:13], data['y'])  # 参数拟合\n",
    "print(clf.coef_)  # 系数\n",
    "print(clf.intercept_)  # 常量\n",
    "# print(clf.predict([[3, 3]]))  # 求预测值\n",
    "\n",
    "print(clf.score(data.iloc[:, 0:13], data['y']))  # R^2，拟合优度\n",
    "print(clf.get_params())  # 获取参数信息\n",
    "print(clf.set_params(fit_intercept=False))  # 重新设置参数 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
